package com.tensquare.search.service;

import com.tensquare.search.dao.ArticleDao;
import com.tensquare.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

@Service
public class ArticleService {

    @Autowired
    private ArticleDao articleDao;


    // 添加
    public void save(Article article) {
        articleDao.save(article);
    }

    // 模糊查询
    public Page<Article> findByTitleOrContentLike(String keywords, int page, int size) {
        Pageable pageable = PageRequest.of(page-1, size);
        Page<Article> pageData = articleDao.findByTitleOrAndContentLike(keywords, keywords, pageable);
        return pageData;
    }
}
